package com.smw.util;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.interfaces.Claim;

import java.util.HashMap;
import java.util.Map;

public class JwtUtil {
    public static String JwtToken(String userName,String passWord){
        Map<String,Object>map=new HashMap<String,Object>();
        map.put("alg","HS256");
        map.put("typ","JWT");
       String token= JWT.create().withHeader(map)
                .withClaim("jname",userName)
                .withClaim("jpwd",passWord)
                .withSubject("阿西迦")
                //.withExpiresAt()
                .sign(Algorithm.HMAC256("axijia"));
        return token;
    }
    public static Map<String,Object> OfToken(String token){
          Map<String,Claim> map= JWT. decode(token).getClaims();
          //System.out.println(map);
          Map<String,Object>result=new HashMap<String,Object>();
          result.put("jname",map.get("jname").asString());
          result.put("jpwd",map.get("jpwd").asString());
          return result;
}
//    public static void main(String[] args) {
//        String token=JwtToken("zjl","123456");
//        System.out.println("token:::"+token);
//        System.out.println("dier:::"+OfToken(token));
//    }



}
